﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RFIDStockManagement.Model.Public;
using RFIDStockManagement.Common.Public.Enums;
using RFIDStockManagement.IDAL;
using RFIDStockManagement.DAL;
using System.Data;

namespace RFIDStockManagement.BLL
{
    /// <summary>
    /// 基础资料逻辑管理类
    /// </summary>
    public class BasicInfoManager
    {
        private static Dictionary<EnumBasicInfo, IBasicInfoAccess> m_dctBasicInfoAccess = new Dictionary<EnumBasicInfo, IBasicInfoAccess>();
        private static IBasicInfoAccess CreateBasicInfoAccess(EnumBasicInfo enumBasicInfo)
        {
            IBasicInfoAccess result = null;
            if (m_dctBasicInfoAccess.ContainsKey(enumBasicInfo))
            {
                result = m_dctBasicInfoAccess[enumBasicInfo];
            }
            else
            {
                result = DalFactory.CreateBasicInfoAccess(enumBasicInfo);
                m_dctBasicInfoAccess[enumBasicInfo] = result;
            }

            return result;
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="info"></param>
        public static BasicModelInfo Save(BasicModelInfo info, EnumBasicInfo enumBasicInfo)
        {
            IBasicInfoAccess access = CreateBasicInfoAccess(enumBasicInfo);
            return access.Save(info);
        }

        /// <summary>
        /// 获取资料列表
        /// </summary>
        /// <param name="dctFilter"></param>
        /// <returns></returns>
        public static DataTable GetList(Dictionary<string, object> dctFilter, EnumBasicInfo enumBasicInfo)
        {
            IBasicInfoAccess access = CreateBasicInfoAccess(enumBasicInfo);
            return access.GetList(dctFilter, true);
        }
        /// <summary>
        /// 模糊资料列表
        /// </summary>
        /// <param name="dctFilter"></param>
        /// <returns></returns>
        public static DataTable Search(Dictionary<string, object> dctFilter, EnumBasicInfo enumBasicInfo)
        {
            IBasicInfoAccess access = CreateBasicInfoAccess(enumBasicInfo);
            return access.Search(dctFilter, true);
        }
        /// <summary>
        /// 读取一个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BasicModelInfo GetOne(long id, EnumBasicInfo enumBasicInfo)
        {
            IBasicInfoAccess access = CreateBasicInfoAccess(enumBasicInfo);
            return access.GetOne(id);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="lstInfo"></param>
        public static List<string> Delete(List<string> lstInfo, EnumBasicInfo enumBasicInfo)
        {
            IBasicInfoAccess access = CreateBasicInfoAccess(enumBasicInfo);
            return access.Delete(lstInfo);
        }
    }
}
